package tt.dz.egobus.servicemanager.vo;

import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.servicemanager.bean.EntityViewVo;
import tt.dz.egobus.servicemanager.entities.BusinessService;
import tt.dz.egobus.servicemanager.entities.BusinessServiceInfo;

import javax.persistence.Column;
import java.util.Date;

/**
 * 业务详细信息Vo
 *
 * @author Jack
 * @date 2017/8/28
 * @name
 * @since 1.0.7
 */
public class BusinessServiceInfoViewVo implements EntityViewVo<BusinessServiceInfo, BusinessServiceInfoViewVo> {
    private static final Logger LOGGER = LoggerFactory.getLogger(BusinessServiceInfoViewVo.class);

    @Override
    public BusinessServiceInfo convert() {
        BusinessServiceInfo pojo = new BusinessServiceInfo();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("BusServiceInfoViewVo -> BusinessServiceInfo bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;

    }

    @Override
    public BusinessServiceInfoViewVo view(BusinessServiceInfo pojo) {
        if (pojo == null) {
            return this;
        }
        BusinessService bs = pojo.getBusinessService();
        this.setBusinessId(pojo.getBusinessId());
        this.setDistance(pojo.getDistance());
        this.setStartX(pojo.getStartX());
        this.setStartY(pojo.getStartY());
        this.setStartAddress(pojo.getStartAddress());
        this.setEndX(pojo.getEndX());
        this.setEndY(pojo.getEndY());
        this.setEndAddress(pojo.getEndAddress());
        this.setCreateTime(pojo.getCreateTime());
        this.setEndTime(pojo.getEndTime());
        this.setRequestStartAddress(pojo.getRequestStartAddress());
        this.setRequestStartX(pojo.getRequestStartX());
        this.setRequestStartY(pojo.getRequestStartY());
        this.setRequestEndAddress(pojo.getRequestEndAddress());
        this.setRequestEndX(pojo.getRequestEndX());
        this.setRequestEndY(pojo.getRequestEndY());
        this.setDriverName(pojo.getDriverName());
        this.setPhoneNumber(pojo.getPhoneNumber());
        this.setBespeakTime(pojo.getBespeakTime());
        this.setUserName(pojo.getUserName());
        this.setUserPhone(pojo.getUserPhone());
        this.setPassengerName(pojo.getPassengerName());
        this.setPassengerPhone(pojo.getPassengerPhone());
        this.setOrverTimeSeconds(pojo.getOrverTimeSeconds());
        // 是否能取消订单
        this.setCheckIsCanCancel(pojo.businessCanAbleDriverCancel());
        if (null != bs) {
            this.setOrderId(bs.getOrderId());
            this.setUserId(bs.getUserId());
            this.setDriverId(bs.getDriverId());
            this.setStatus(bs.getStatus());
            this.setIsValidate(bs.getIsValidate());
            this.setBusinessCode(bs.getBusinessCode());
            this.setServiceFee(bs.getServiceFee());
            this.setRequestType(bs.getRequestType());
            this.setIsRideSelf(bs.getRideSelf());
            this.setIsOverTime(bs.getOverTime());
        }
        BusServiceViewVo busServiceViewVo = pojo.convertBusService();
        if (null != busServiceViewVo) {
            this.setBusServiceInfo(busServiceViewVo);
        }
        return this;
    }


    /**
     * 业务流水号 且是1:1的关系
     */
    @NotBlank(message = "当前业务流水号不能为空")
    private String businessId;


    /**
     * 当前行程数单位M
     */
    private double distance;


    /**
     * 行程起点经度
     */
    private double startX;

    /**
     * 行程起点纬度
     */
    private double startY;

    /**
     * 行程开始地点
     */
    private String startAddress;
    /**
     * 行程结束经度
     */
    private double endX;

    /**
     * 行程结束纬度
     */
    private double endY;

    /**
     * 行程结束地点
     */
    private String endAddress;


    /**
     * 创建时间
     */
    private Date createTime;


    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 用户请求的开始地址
     */
    private String requestStartAddress;

    /**
     * 用户请求开始的x,经度
     */
    private double requestStartX;

    /**
     * 用户请求开始的y,纬度
     */
    private double requestStartY;

    /**
     * 用户请求的结束地址
     */
    private String requestEndAddress;

    /**
     * 用户请求结束的x,经度
     */
    private double requestEndX;

    /**
     * 用户请求结束的y,纬度
     */
    private double requestEndY;


    /**
     * 司机真实姓名
     */
    private String driverName;


    /**
     * 司机手机号码
     **/
    private String phoneNumber;

    /**
     * 预约时间,若当前是预约类别,则当前预约时间不能空
     */
    private Date bespeakTime;

    /**
     * 请求人名称
     */
    private String userName;

    /**
     * 请求人手机
     */
    private String userPhone;

    /**
     * 乘车人名称
     */
    private String passengerName;

    /**
     * 乘车人手机
     */
    private String passengerPhone;

    /**
     * 超时的时间
     * 单位秒
     */
    private double orverTimeSeconds;

    /**
     * 当前订单id 且是1:1的关系
     */
    private String orderId;


    /**
     * 请求用户的id
     */
    private String userId;


    /**
     * 司机ID
     */
    private String driverId;


    /**
     * 状态 ,20:开始;30:进行;40:完毕;50：取消;60:下线;-10:异常
     * 部分同{@link tt.dz.egobus.servicemanager.entities.DriverRegisterBusRelative.RelativeStatus}一样
     */
    private int status;


    /**
     * 是否失效
     */
    @Column(name = "is_validate")
    private boolean isValidate;

    /**
     * 业务服务号
     */
    private int businessCode;

    /**
     * 服务费用
     */
    private double serviceFee;

    /**
     * 用户请求类型
     * 1.及时请求派车
     * 2.预约请求派车
     */
    private int requestType = 1;

    /**
     * 是否自己用车
     */
    private Boolean isRideSelf = true;

    /**
     * 当前行程是否超时了
     */
    private Boolean isOverTime = false;

    /**
     * 校验是否能取消
     * 备注：
     * true:能
     * false：不能
     */
    private Boolean checkIsCanCancel = false;

    /**
     * 费用计价详情
     */
    private BusServiceViewVo busServiceInfo;

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public double getStartX() {
        return startX;
    }

    public void setStartX(double startX) {
        this.startX = startX;
    }

    public double getStartY() {
        return startY;
    }

    public void setStartY(double startY) {
        this.startY = startY;
    }

    public String getStartAddress() {
        return startAddress;
    }

    public void setStartAddress(String startAddress) {
        this.startAddress = startAddress;
    }

    public double getEndX() {
        return endX;
    }

    public void setEndX(double endX) {
        this.endX = endX;
    }

    public double getEndY() {
        return endY;
    }

    public void setEndY(double endY) {
        this.endY = endY;
    }

    public String getEndAddress() {
        return endAddress;
    }

    public void setEndAddress(String endAddress) {
        this.endAddress = endAddress;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getRequestStartAddress() {
        return requestStartAddress;
    }

    public void setRequestStartAddress(String requestStartAddress) {
        this.requestStartAddress = requestStartAddress;
    }

    public double getRequestStartX() {
        return requestStartX;
    }

    public void setRequestStartX(double requestStartX) {
        this.requestStartX = requestStartX;
    }

    public double getRequestStartY() {
        return requestStartY;
    }

    public void setRequestStartY(double requestStartY) {
        this.requestStartY = requestStartY;
    }

    public String getRequestEndAddress() {
        return requestEndAddress;
    }

    public void setRequestEndAddress(String requestEndAddress) {
        this.requestEndAddress = requestEndAddress;
    }

    public double getRequestEndX() {
        return requestEndX;
    }

    public void setRequestEndX(double requestEndX) {
        this.requestEndX = requestEndX;
    }

    public double getRequestEndY() {
        return requestEndY;
    }

    public void setRequestEndY(double requestEndY) {
        this.requestEndY = requestEndY;
    }

    public String getDriverName() {
        return driverName;
    }

    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Date getBespeakTime() {
        return bespeakTime;
    }

    public void setBespeakTime(Date bespeakTime) {
        this.bespeakTime = bespeakTime;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getPassengerName() {
        return passengerName;
    }

    public void setPassengerName(String passengerName) {
        this.passengerName = passengerName;
    }

    public String getPassengerPhone() {
        return passengerPhone;
    }

    public void setPassengerPhone(String passengerPhone) {
        this.passengerPhone = passengerPhone;
    }

    public double getOrverTimeSeconds() {
        return orverTimeSeconds;
    }

    public void setOrverTimeSeconds(double orverTimeSeconds) {
        this.orverTimeSeconds = orverTimeSeconds;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isValidate() {
        return isValidate;
    }

    public void setIsValidate(boolean isvalidate) {
        isValidate = isvalidate;
    }

    public int getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(int businessCode) {
        this.businessCode = businessCode;
    }

    public double getServiceFee() {
        return serviceFee;
    }

    public void setServiceFee(double serviceFee) {
        this.serviceFee = serviceFee;
    }

    public int getRequestType() {
        return requestType;
    }

    public void setRequestType(int requestType) {
        this.requestType = requestType;
    }

    public Boolean getRideSelf() {
        return isRideSelf;
    }

    public void setIsRideSelf(Boolean isrideSelf) {
        isRideSelf = isrideSelf;
    }

    public Boolean getOverTime() {
        return isOverTime;
    }

    public void setIsOverTime(Boolean isoverTime) {
        isOverTime = isoverTime;
    }

    public BusServiceViewVo getBusServiceInfo() {
        return busServiceInfo;
    }

    public void setBusServiceInfo(BusServiceViewVo busServiceInfo) {
        this.busServiceInfo = busServiceInfo;
    }


    public String getDriverId() {
        return driverId;
    }

    public void setDriverId(String driverId) {
        this.driverId = driverId;
    }

    public Boolean getCheckIsCanCancel() {
        return checkIsCanCancel;
    }

    public void setCheckIsCanCancel(Boolean checkIsCanCancel) {
        this.checkIsCanCancel = checkIsCanCancel;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BusinessServiceInfoViewVo that = (BusinessServiceInfoViewVo) o;

        if (Double.compare(that.distance, distance) != 0) return false;
        if (Double.compare(that.startX, startX) != 0) return false;
        if (Double.compare(that.startY, startY) != 0) return false;
        if (Double.compare(that.endX, endX) != 0) return false;
        if (Double.compare(that.endY, endY) != 0) return false;
        if (Double.compare(that.requestStartX, requestStartX) != 0) return false;
        if (Double.compare(that.requestStartY, requestStartY) != 0) return false;
        if (Double.compare(that.requestEndX, requestEndX) != 0) return false;
        if (Double.compare(that.requestEndY, requestEndY) != 0) return false;
        if (Double.compare(that.orverTimeSeconds, orverTimeSeconds) != 0) return false;
        if (status != that.status) return false;
        if (isValidate != that.isValidate) return false;
        if (businessCode != that.businessCode) return false;
        if (Double.compare(that.serviceFee, serviceFee) != 0) return false;
        if (requestType != that.requestType) return false;
        if (businessId != null ? !businessId.equals(that.businessId) : that.businessId != null) return false;
        if (startAddress != null ? !startAddress.equals(that.startAddress) : that.startAddress != null) return false;
        if (endAddress != null ? !endAddress.equals(that.endAddress) : that.endAddress != null) return false;
        if (createTime != null ? !createTime.equals(that.createTime) : that.createTime != null) return false;
        if (endTime != null ? !endTime.equals(that.endTime) : that.endTime != null) return false;
        if (requestStartAddress != null ? !requestStartAddress.equals(that.requestStartAddress) : that
                .requestStartAddress != null)
            return false;
        if (requestEndAddress != null ? !requestEndAddress.equals(that.requestEndAddress) : that.requestEndAddress !=
                null)
            return false;
        if (driverName != null ? !driverName.equals(that.driverName) : that.driverName != null) return false;
        if (phoneNumber != null ? !phoneNumber.equals(that.phoneNumber) : that.phoneNumber != null) return false;
        if (bespeakTime != null ? !bespeakTime.equals(that.bespeakTime) : that.bespeakTime != null) return false;
        if (userName != null ? !userName.equals(that.userName) : that.userName != null) return false;
        if (userPhone != null ? !userPhone.equals(that.userPhone) : that.userPhone != null) return false;
        if (passengerName != null ? !passengerName.equals(that.passengerName) : that.passengerName != null)
            return false;
        if (passengerPhone != null ? !passengerPhone.equals(that.passengerPhone) : that.passengerPhone != null)
            return false;
        if (orderId != null ? !orderId.equals(that.orderId) : that.orderId != null) return false;
        if (userId != null ? !userId.equals(that.userId) : that.userId != null) return false;
        if (driverId != null ? !driverId.equals(that.driverId) : that.driverId != null) return false;
        if (isRideSelf != null ? !isRideSelf.equals(that.isRideSelf) : that.isRideSelf != null) return false;
        if (isOverTime != null ? !isOverTime.equals(that.isOverTime) : that.isOverTime != null) return false;
        if (checkIsCanCancel != null ? !checkIsCanCancel.equals(that.checkIsCanCancel) : that.checkIsCanCancel != null)
            return false;
        return busServiceInfo != null ? busServiceInfo.equals(that.busServiceInfo) : that.busServiceInfo == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = businessId != null ? businessId.hashCode() : 0;
        temp = Double.doubleToLongBits(distance);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(startX);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(startY);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (startAddress != null ? startAddress.hashCode() : 0);
        temp = Double.doubleToLongBits(endX);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(endY);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (endAddress != null ? endAddress.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (endTime != null ? endTime.hashCode() : 0);
        result = 31 * result + (requestStartAddress != null ? requestStartAddress.hashCode() : 0);
        temp = Double.doubleToLongBits(requestStartX);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(requestStartY);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (requestEndAddress != null ? requestEndAddress.hashCode() : 0);
        temp = Double.doubleToLongBits(requestEndX);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(requestEndY);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (driverName != null ? driverName.hashCode() : 0);
        result = 31 * result + (phoneNumber != null ? phoneNumber.hashCode() : 0);
        result = 31 * result + (bespeakTime != null ? bespeakTime.hashCode() : 0);
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (userPhone != null ? userPhone.hashCode() : 0);
        result = 31 * result + (passengerName != null ? passengerName.hashCode() : 0);
        result = 31 * result + (passengerPhone != null ? passengerPhone.hashCode() : 0);
        temp = Double.doubleToLongBits(orverTimeSeconds);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (orderId != null ? orderId.hashCode() : 0);
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (driverId != null ? driverId.hashCode() : 0);
        result = 31 * result + status;
        result = 31 * result + (isValidate ? 1 : 0);
        result = 31 * result + businessCode;
        temp = Double.doubleToLongBits(serviceFee);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + requestType;
        result = 31 * result + (isRideSelf != null ? isRideSelf.hashCode() : 0);
        result = 31 * result + (isOverTime != null ? isOverTime.hashCode() : 0);
        result = 31 * result + (checkIsCanCancel != null ? checkIsCanCancel.hashCode() : 0);
        result = 31 * result + (busServiceInfo != null ? busServiceInfo.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "BusinessServiceInfoViewVo{" + "businessId='" + businessId + '\'' + ", distance=" + distance + ", " +
                "startX=" + startX + ", startY=" + startY + ", startAddress='" + startAddress + '\'' + ", endX=" +
                endX + ", endY=" + endY + ", endAddress='" + endAddress + '\'' + ", createTime=" + createTime + ", "
                + "endTime=" + endTime + ", requestStartAddress='" + requestStartAddress + '\'' + ", requestStartX="
                + requestStartX + ", requestStartY=" + requestStartY + ", requestEndAddress='" + requestEndAddress +
                '\'' + ", requestEndX=" + requestEndX + ", requestEndY=" + requestEndY + ", driverName='" +
                driverName + '\'' + ", phoneNumber='" + phoneNumber + '\'' + ", bespeakTime=" + bespeakTime + ", " +
                "userName='" + userName + '\'' + ", userPhone='" + userPhone + '\'' + ", passengerName='" +
                passengerName + '\'' + ", passengerPhone='" + passengerPhone + '\'' + ", orverTimeSeconds=" +
                orverTimeSeconds + ", orderId='" + orderId + '\'' + ", userId='" + userId + '\'' + ", driverId='" +
                driverId + '\'' + ", status=" + status + ", isValidate=" + isValidate + ", businessCode=" +
                businessCode + ", serviceFee=" + serviceFee + ", requestType=" + requestType + ", isRideSelf=" +
                isRideSelf + ", isOverTime=" + isOverTime + ", checkIsCanCancel=" + checkIsCanCancel + ", " +
                "busServiceInfo=" + busServiceInfo + '}';
    }
}
